<%--
  Created by IntelliJ IDEA.
  User: HW
  Date: 2018/4/19
  Time: 1:04
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<script type="text/javascript" src="../../js/jquery-1.11.0.js"></script>
<script type="text/javascript" src="../../js/jquery-migrate-1.2.1.js"></script>
<script src="../../js/jquery.js"></script>
<head>
    <title>乡镇图书管理系统</title>
</head>
<body style="background:cornflowerblue;height: 100%">
<div align="center">
    <table style="width: auto" border="1">
        <thead>
        <tr>
            <td align="center" colspan="4">
                <h1>乡镇图书管理系统</h1>
            </td>
        </tr>
        </thead>
        <tr>
            <td>
                <form action="/book/toTsgl">
                    <input id="bookId" type="hidden" name="bookId"/>
                    <p>图书名称<input type="text" id="bookName" name="bookName"/></p>
                    <p>图书类型<input list="typelist" id="bookType" name="bookType"/></p>
                    <p>图书作者<input type="text" id="author" name="author"/></p>
                    <p>借书用户<input type="text" id="userName" name="userName"/></p>
                    <p>借出日期<input type="date" id="outDate" name="outDate"/></p>
                    <p>归还日期<input type="date" id="inDate" name="inDate"/></p>
                    <p style="text-align: center;width: 100%"><input type="submit" value="提交" onclick="return outbook()"></p>
                </form>
            </td>
        </tr>
        <datalist id="typelist">
            <option>1</option>
            <option>2</option>
            <option>3</option>
            <option>4</option>
            <option>5</option>
        </datalist>
    </table>
</div>
</body>
<script type="text/javascript">
    window.onload = function () {
        $("#bookName").val("<%=request.getAttribute("bookName")%>");
        $("#bookType").val("<%=request.getAttribute("bookType")%>");
        $("#author").val("<%=request.getAttribute("author")%>");
        $("#bookId").val("<%=request.getAttribute("bookId")%>");

    }

    function outbook(form) {
        var state = confirm("确定借出？");
        if (state) {
            $.ajax({
                    type: "post",
                    url: "/book/outBook",
                    dataType: "json",
                    data: {
                        bookName: $("#bookName").val(),
                        bookType: $("#bookType").val(),
                        author: $("#author").val(),
                        outDate: $("#outDate").val(),
                        inDate: $("#inDate").val(),
                        bookId: $("#bookId").val(),
                        userName: $("#userName").val()
                    },
                    success: function (data) {
                        if (data == 1) {
                            alert("操作成功");
                            return true;
                        } else {
                            alert("用户不存在或借还日期错误");
                        }
                    }
                }
            );
        }
    }
</script>
</html>
